package com.service.gmall.product.controller;

import com.service.gmall.common.result.Result;
import com.service.gmall.model.product.BaseCategory1;
import com.service.gmall.model.product.BaseCategory2;
import com.service.gmall.model.product.BaseCategory3;
import com.service.gmall.product.service.BaseCategory2Service;
import com.service.gmall.product.service.BaseCategory3Service;
import com.service.gmall.product.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author alpha
 * @className: CategoryController
 * @date 2022/8/22 21:44
 * @Description： 三级分类接口
 */
@Api(tags = "三级分类接口")
@RestController
@RequestMapping("/admin/product")
//admin/product/getCategory1
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    BaseCategory2Service baseCategory2Service;

    @Autowired
    BaseCategory3Service baseCategory3Service;

//    /admin/product/getCategory1
    @ApiOperation("查询一级目录")
    @GetMapping("/getCategory1")
    public Result getCategory1() {
        List<BaseCategory1> list = categoryService.list();
        return Result.ok(list);
    }


    //    admin/product/getCategory2/1
    @ApiOperation("查询二级目录")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") String category1Id) {
        List<BaseCategory2> category2List = baseCategory2Service.getCategory2(category1Id);
        return Result.ok(category2List);
    }

    //    admin/product/getCategory3/1
    @ApiOperation("查询三级目录")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3> category3List = baseCategory3Service.getCategory3(category2Id);
        return Result.ok(category3List);
    }
}
